#ifndef _bvhmotion_h_included_
#define _bvhmotion_h_included_
#include <d3dx9.h>
#include <d3d9.h>
#include <string>
#include <Vector>
#include "Node.h"
#include "ModelPrimitive.h"
#include <fstream>
#include <iostream> 
#include <dinput.h> 
#include <D3dx9math.h>

class Node;
class ModelPrimitive;

//This class is responsible for maintaining the state
//of a model
class BVHMotion
{

	protected:
	Node* mRoot;

	int mDataCount;

	int mFrameCount;
	float mFrameRate;
	
	float mFrameTime;

	vector<Node*>* mOrder;

public:
	
	BVHMotion();

	//Recursive function for reading in joints
	Node* CreateJoint(ifstream* fp_in);

	void SetRoot(Node* pRoot){mRoot = pRoot;}
	Node* GetRoot(){return mRoot;}

	void SetFrameCount(int pNum){mFrameCount = pNum;}
	int GetFrameCount(){return mFrameCount;}

	void SetDataCount(int pNum){mDataCount = pNum;}
	int GetDataCount(){return mDataCount;}

	void SetFrameRate(float pNum){mFrameRate = pNum;}
	float GetFrameRate(){return mFrameRate;}

	void SetFrameTime(float pNum){mFrameTime = pNum;}
	float GetFrameTime(){return mFrameTime;}

	vector<Node*>* GetOrder(){return mOrder;}

	void Update(float pElapsedTime);
	void Draw(LPDIRECT3DDEVICE9 d3ddev, LPD3DXMATRIXSTACK pStack);

	void LoadFromFile(string loc);
	int ChannelStringToInt(string channel);

		void Tokenize(const string& str,
                      vector<string>& tokens,
                      const string& delimiters = " ")
	{
		tokens.clear();
		// Skip delimiters at beginning.
		string::size_type lastPos = str.find_first_not_of(delimiters, 0);
		// Find first "non-delimiter".
		string::size_type pos     = str.find_first_of(delimiters, lastPos);

		while (string::npos != pos || string::npos != lastPos)
		{
			// Found a token, add it to the vector.
			tokens.push_back(str.substr(lastPos, pos - lastPos));
			// Skip delimiters.  Note the "not_of"
			lastPos = str.find_first_not_of(delimiters, pos);
			// Find next "non-delimiter"
			pos = str.find_first_of(delimiters, lastPos);
		}
	}
};
#endif
